﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FRW.CreateTestDirectory
{
    public partial class Progress : Form, IStatusUi
    {
        public Progress()
        {
            InitializeComponent();

            label1.Text = "";
        }

        public void DisplayLogText(string text)
        {
            throw new NotImplementedException();
        }

        private void UpdateStatus(Label label, string statusMessage)
        {
            if (label.InvokeRequired)
            {
                label.Invoke(new Action(() => label.Text = statusMessage));
            }
            else
            {
                label.Text = statusMessage;
            }
        }

        private void UpdateProgress(ProgressBar progressBar, int percentage)
        {
            if (progressBar.InvokeRequired)
            {
                progressBar.Invoke(new Action(() => progressBar.Value = progressBar.Maximum * percentage / 100));
            }
            else
            {
                progressBar.Value = progressBar.Maximum * percentage / 100;
            }
        }

        public void DisplayStatusText(string text)
        {
            UpdateStatus(label1, text);
        }

        public void PercentageComplete(int percentage)
        {
            UpdateProgress(progressBar1, percentage);
        }


        public void Finished()
        {
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void _cancelButton_Click(object sender, EventArgs e)
        {
            DialogResult = System.Windows.Forms.DialogResult.Cancel;
        }
    }
}
